package LeetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName interview
 * @Description: TODO
 * @date ${DAT}15:32
 */
public class LeetCode113 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> pathSum(TreeNode root, int sum) {
        List<Integer> list = new ArrayList<>();
        pathSum(root,sum,list);
        return res;
    }

    public void pathSum(TreeNode root,int sum,List<Integer> list){
        if (root == null){
            return;
        }
        list.add(root.val);
        if (root.left == null && root.right == null && sum == root.val){
            res.add(new ArrayList<>(list));
        }


        pathSum(root.left,sum - root.val,list);
        pathSum(root.right,sum - root.val,list);
        list.remove(list.size() - 1);
    }
}
